home *** CD-ROM | disk | FTP | other *** search
- /* ----------------------------------------------------------------------
-
- cicnButton CDEF
- version 1.3.2
-
- Written by: Paul Celestin
-
- Copyright © 1993-1997 Celestin Company, Inc.
-
- This CDEF displays a cicn whose resource ID is derived from the
- value field of the CNTL. The min, max, and refcon fields are not
- used and should therefore not be set.
-
- No parameters required!
-
- 940320 - 1.0.0 - initial release
- 940531 - 1.0.1 - Changed to work on machines without color Quickdraw
- The icon family needs two B&W additions which are ICON resources
- rather than cicns.
- 951215 - 1.3.0 - updated for CW7
- 960704 - 1.3.1 - updated for CW9
- 970815 - 1.3.2 - updated for CW Pro 1
-
- ---------------------------------------------------------------------- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <ToolUtils.h>
- #include <Icons.h>
- #include <Controls.h>
- #include <Gestalt.h>
-
- #define INVERTED_ICON 1
-
-
- /* ----------------------------------------------------------------------
- prototypes
- ---------------------------------------------------------------------- */
- pascal long main(short, ControlHandle, short, long);
- void drawIt(ControlHandle, short);
- long testIt(ControlHandle, Point);
-
-
- /* ----------------------------------------------------------------------
- main
- ---------------------------------------------------------------------- */
- pascal long main (short variation, ControlHandle theControl, short message, long param)
-
- {
- long returnValue = 0L;
- char state = HGetState((Handle)theControl);
- Str255 copyright = "\pCopyright © 1993-1996 Celestin Company, Inc.";
-
- switch(message)
- {
- case drawCntl:
- drawIt(theControl,variation);
- case testCntl:
- returnValue = testIt(theControl, *(Point *) ¶m);
- case calcCRgns:
- break;
- case initCntl:
- break;
- case dispCntl:
- break;
- case posCntl:
- break;
- case thumbCntl:
- break;
- case dragCntl:
- break;
- case autoTrack:
- break;
- case calcCntlRgn:
- break;
- case calcThumbRgn:
- break;
- default:
- break;
- }
-
- HSetState((Handle)theControl,state);
-
- return(returnValue); /* tell them what happened */
- }
-
-
- /* ----------------------------------------------------------------------
- drawIt - here is where we actually draw the control
- ---------------------------------------------------------------------- */
- static void drawIt (ControlHandle control, short variation)
- {
- Rect myRect;
- short myICONID;
- CIconHandle myICON;
- Handle myBWICON;
- GrafPtr myPort;
- Pattern myGray;
- PenState oldPenState;
- Str255 myTitle;
- int savedFont,
- savedSize,
- savedMode;
- OSErr myErr;
- Boolean hasColorQD;
- long feature;
-
- GetPort(&myPort); /* save off the current port */
-
- if (!(*control)->contrlVis) /* if not visible, do nothing */
- return;
-
- /* find out if Color QD is present */
- myErr = Gestalt(gestaltQuickdrawFeatures, &feature);
- hasColorQD = ((myErr == noErr) && BitTst(&feature, 31 - gestaltHasColor));
-
- myICONID = GetCtlValue(control); /* base ID is stored in the value field */
-
- if ((*control)->contrlHilite == inButton)
- myICONID = myICONID + INVERTED_ICON; /* invert while tracking */
-
- myRect = (*control)->contrlRect; /* get the rectangle of the control */
-
- if ( hasColorQD )
- {
- myICON = GetCIcon(myICONID); /* get the appropriate cicn resource */
-
- if ( myICON == 0L ) /* make sure the cicn exists */
- return;
-
- EraseRect(&myRect); /* erase before drawing */
-
- PlotCIcon(&myRect,myICON); /* draw the cicn */
- }
- else /* no color QD case */
- {
- myBWICON = GetIcon(myICONID);
-
- if ( myBWICON == 0L )
- return;
-
- EraseRect(&myRect);
-
- PlotIcon(&myRect, myBWICON);
- }
-
- savedFont = myPort->txFont; /* save of values before drawing title */
- savedSize = myPort->txSize;
- savedMode = myPort->txMode;
-
- TextFont(geneva); /* change font to Geneva 9 point */
- TextSize(9);
- TextMode(srcOr);
- BlockMove(((*control)->contrlTitle),myTitle,((*control)->contrlTitle)[0] + 1);
- MoveTo((myRect.right+myRect.left) / 2 - StringWidth(myTitle) / 2,myRect.bottom + 12);
- DrawString(myTitle); /* draw the title */
-
- TextFont(savedFont); /* restore the values that were saved */
- TextSize(savedSize);
- TextMode(savedMode);
-
- switch (variation)
- {
- default:
- break;
- }
-
- if ((*control)->contrlHilite == 255) /* gray out the cicn */
- {
- GetPenState(&oldPenState);
- PenNormal();
- GetIndPattern(&myGray,0,4);
- PenPat(&myGray);
- PenMode(patBic);
- PaintRect(&myRect);
- SetPenState(&oldPenState);
- }
- }
-
-
- /* ----------------------------------------------------------------------
- testIt - test for mouse hits within control
- ---------------------------------------------------------------------- */
- static long testIt (ControlHandle control, Point myPoint)
-
- {
- Rect myRect;
-
- myRect = (*control)->contrlRect;
-
- if (
- ((*control)->contrlVis != 0) &&
- ((*control)->contrlHilite != 255) &&
- (PtInRect(myPoint,&myRect))
- )
- return(inButton);
- else
- return(0);
- }
-